package schoiolword;

import java.util.Scanner;

public class Text {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int[] arr = {1,2,3};
            System.out.println("请输入数组的下标: ");
            int index = sc.nextInt();
            System.out.println(arr[index]);

            System.out.println("请输入除数: ");
            int x = sc.nextInt();
            int y = 4/x;
            System.out.println("y=" + y);
        }catch (ArithmeticException ae) { // 捕获算术异常
            System.out.println(ae.getMessage());  //使用getMessage
            System.out.println("处理算术异常");   //程序退出且finally执行
            //return;
        }catch (ArrayIndexOutOfBoundsException aibe) { //捕获下标越界异常
            System.out.println(aibe.toString()); //使用toString打印异常信息
            System.out.println("处理数组下标越界异常");
            System.exit(1);
        }catch (Exception e) {  //其他异常处理
            e.printStackTrace(System.out);
        }finally {
            System.out.println("执行finally程序");
        }
        System.out.println("程序向下执行!");
    }
}
